package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Tag(name = "角色接口")
@RequestMapping("/admin/system/sysRole")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    @Operation(summary = "分页查询角色信息")
    public Result<PageInfo<SysRole>> findByPage(String roleName,
                                                @PathVariable Integer pageNum,
                                                @PathVariable Integer pageSize) {

        PageInfo<SysRole> pageInfo = sysRoleService.findByPage(roleName, pageNum, pageSize);

        return Result.OK(pageInfo);
    }

    @PostMapping("/saveSysRole")
    @Operation(summary = "添加角色信息")
    public Result SaveSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.saveSysRole(sysRole);
        return Result.OK(null);
    }

    @PutMapping("/updateSysRole")
    @Operation(summary = "修改角色信息")
    public Result UpdateSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.updateSysRole(sysRole);
        return Result.OK(null);
    }

    @DeleteMapping("/deleteById/{roleId}")
    @Operation(summary = "删除角色信息")
    public Result deletedById(@PathVariable Long roleId) {
        sysRoleService.deletedById(roleId);
        return Result.OK(null);
    }

    @GetMapping("/findAllRoles/{userId}")
    @Operation(summary = "查询用户所有角色")
    public Result<Map<String, Object>> findAllRoles(@PathVariable Long userId){
        Map<String, Object> resultMap = sysRoleService.findAllRoles(userId);
        return Result.OK(resultMap);
    }
}
